package mapper;


import com.jyz.javabean.User;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

public interface UserMapper {
    @Select({"select * from user"})
    List<User> selectAll();


    @Update({
            "<script>",
            "update user",
            "<set>",
            "  <if test='user.username != null'>username = #{user.username},</if>",
            "  <if test='user.password != null'>password = #{user.password},</if>",
            "  <if test='user.phone != null'>phone = #{user.phone},</if>",
            "</set>",
            "where uid = #{user.uid}",
            "</script>"
    })
    int updateByUser(@Param("user") User user);


    @Delete("<script>" +
            "delete from user where uid in " +
            "<foreach collection='array' item='uid' separator=',' open='(' close=')'>" +
            "#{uid}" +
            "</foreach>" +
            "</script>")
    int deleteByArray(int[] ids);

}

